package com.sensePlusVR.activity.user;

import android.view.View;
import android.widget.TextView;

import com.sensePlusVR.base.BaseActivity;
import com.sensePlusVR.main.R;
import com.sensePlusVR.net.NetRequestManager;
import com.sensePlusVR.utils.AppManager;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.MyLog;
import com.sensePlusVR.utils.MyPageJump;
import com.sensePlusVR.utils.MySharedPreferences;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_register_verify_email)
public class RegisterVerifyEmailActivity extends BaseActivity {
	private static final String TAG = RegisterVerifyEmailActivity.class
			.getSimpleName();
	@ViewInject(R.id.title_bar_title_tv)
	private TextView title_bar_title_tv;
	private String userName;
	private String password;

	@Override
	public void setMyContentView() {
		x.view().inject(this);
	}
	
	@Override
	public void beforeView() {
		super.beforeView();
          userName =  MySharedPreferences.getString2(this,MySharedPreferences.NAME_NOT_CLEAR, Constant.REGISTER_TEMP_EMAIL);
          password = MySharedPreferences.getString2(this, MySharedPreferences.NAME_NOT_CLEAR, Constant.REGISTER_TEMP_PASSWORD);
          
          MyLog.d(TAG, "userName : " + userName + " password : " + password);
	}

	@Override
	public void initView() {
		super.initView();
		AppManager.getInstance().addActivity(this);
		title_bar_title_tv.setText(getResources().getString(
				R.string.login_signup));
	}

	@Event(value = { R.id.title_bar_left_ib, R.id.verify_email_verified,
			R.id.verify_email_send_again })
	private void setViewOnClick(View view) {
		switch (view.getId()) {
		case R.id.title_bar_left_ib:
			AppManager.getInstance().finishActivity(this);
			break;
		// 验证过直接登陆
		case R.id.verify_email_verified:
			MyLog.d(TAG, "verify_email_verified");
			if (userName != null && password != null) {
				NetRequestManager.startLoginRequestResult(
						RegisterVerifyEmailActivity.this, userName, password);
			} else {
				MyPageJump.pageJump(RegisterVerifyEmailActivity.this,
						LoginActivity.class);
				AppManager.getInstance().finishActivity(this);
				MyLog.d(TAG, "userName or password is null...");
			}
			break;
		// 重新发送验证码
		case R.id.verify_email_send_again:
			MyLog.d(TAG, "verify_email_send_again");
			// TODO 重新发送验证码接口
			NetRequestManager.startSendVerifyAgain(this, userName, password);
			break;
		}

	}
}
